package com.mzz.behavior.fatherandson.template;

/**
 * 格式化抽象类
 *
 * @author xushijian
 * @date 18/5/16
 */
public abstract class AbstractFormatter {

    public String formatBook(Book book) {
        beforeFormat();
        String result = format(book);
        afterFormat();
        return result;
    }

    protected void beforeFormat() {
        System.out.println("format begins");
    }

    /**
     * 格式化方法
     *
     * @param book 书
     * @return 格式化后字符串
     */
    protected abstract String format(Book book);

    protected void afterFormat() {
        System.out.println("format finished");
    }
}
